import os
import random
def generate_diet_plan(user_input):
    """
    B成员
    功能点1：编写一个函数，先调用成员 C 的读取全部食谱的函数获取全部食谱，再根据成员 A 的输入，找出合适的食物组合。
    功能点2：根据找出的食物组合，生成一周的饮食计划，然后返回该计划。
    """
    target = user_input["目标"]
    preference = user_input["喜好"]

    all_foods = read_from_file()
    for target_1 in all_foods.keys():
        if target == target_1:
            for preference_1 in all_foods[target_1].keys():
                if preference == preference_1:
                    # 一周的食谱
                    diet_plan = {}
                    for day in ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]:
                        # 随机选择早餐、午餐、晚餐的食物
                        breakfast = all_foods[target_1][preference_1][
                            random.randint(0, len(all_foods[target_1][preference_1]) - 1)]
                        lunch = all_foods[target_1][preference_1][
                            random.randint(0, len(all_foods[target_1][preference_1]) - 1)]
                        dinner = all_foods[target_1][preference_1][
                            random.randint(0, len(all_foods[target_1][preference_1]) - 1)]
                        # 将每天的食物组合存入字典中
                        diet_plan[day] = {"早餐": breakfast, "午餐": lunch, "晚餐": dinner}

                    return diet_plan
